
package com.scalar.chiptrack.operations.packingslip.forms;

import java.util.HashMap;
import java.util.ArrayList;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.commons.ClientInfo;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.utils.StringUtils;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;


public class ShippingAdviseForm extends ChipTrackActionForm
{

    private int mCustomerShippingId = -1;
    private int mSalesOrderId = -1;
    private String mNumber = null;
    private String mSalesOrderNumber = null;
    private String m_customerName = null;
    private String mPONumber = null;
    private String mWeight = null;
    private String mDeliveryTerms = null;
    private String mCartonCount = null;
    private String mTracking[] = null;
    private String mShippingMethod = null;
    private String mInvoiceNumber = null;
    private String mFlightNumber = null;
    private String mFlightRoute = null;
    private String mEtd = null;
    private String mEta = null;
    private String mHawb = null;
    private String mMawb = null;
    private String mShowSendShipAlertLink = null;
    private HashMap mPulledLotMap = null;
    private String mstatus = null; // Added by Krishna Prasad on 08 May 2004
    private String mPaletteCount = null;  //Added by Varma on 15 oct 2004
    private String mPackedby = null; // Added by Gandhi on 8th Dec 2004
    private String mTitle = null; // Added by Gandhi on 8th Dec 2004

    private boolean     mDropShippment = false;
    private ArrayList   mLineItems = null;
    private int 	    mshippingFromLocationId = -1;
    private String 	    mshipDate = null;
    private HashMap     mfinalInventoryDataMap = null;
    private String 	    mshippingInstructions = null;
	private String      mcomments = null ;
    private String      mgeneratedPackingSlipPdfURL = null ;
    private String      mgeneratedCommercialInvoicePdfURL = null ;
    private String      mfreightInstructions = null;
    private int         odmId = -1;

    private String      odm = null;
    private boolean     confrimPackingSlip = false;
    private ClientInfo  clientInfo = null;
    private String      clientName = null;
    private String      vendorName = null;
    private String 	    contactPerson = null;
    private String      supplierNumber = null;
    private String      odmSupplierNumber = null;
    private int 	    shippingToAddressId = -1;
    private int 	    billingAddressId = -1;
    private int 	    shippingFromAddressId = -1;
    private String 	    billingAddress = null;
	private String 	    shippingAddress = null;
    private Address     m_shippingAddressObject = null;
    private Address     m_shippersAddressObject = null;
    private Address     m_billingAddressObject = null;
    private HashMap     finalInventoryDataMapView = null;
    private boolean     viewInventory = false;
    private boolean     modifyInventory = false;
    private boolean     runAdaptor = false;
    private String 	    externalUserId = null;
    private String      letterOfCreditNo = null;
    private boolean     isSample = false;
    private Address shippingVendorAddressObject;
    private boolean isConsignment;
    private String customerNumber;
    private String weightType       = null;
    private String uomPkgDimension  = null;
    private String packageDimension = null;
    private String grossWeight      = null;
    private String flightNumberTwo  = null;
    private String flightNumberOne  = null;
    private String countryOfFabOrigin   = null;
    private String countryOfAssyOrigin  = null;

    public ShippingAdviseForm()
    {
         mLineItems = new ArrayList();
    }

    public ShippingAdviseForm( String number,
                               int customerShippingId,
                               int salesOrderId,
                               String salesOrderNumber,
                               String customerName,
                               String poNumber,
                               String invoiceNumber,
                               String deliveryTerms,
                               String cartonCount,
                               String weight,
                               String tracking[],
                               String shippingMethod,
                               String flightNumber,
                               String flightRoute,
                               String etd,
                               String eta,
                               String hawb,
                               String mawb )
    {
        mNumber = number;
        mCustomerShippingId = customerShippingId;
        mSalesOrderId = salesOrderId;
        mSalesOrderNumber = salesOrderNumber;
        m_customerName = customerName;
        mPONumber = poNumber;
        mInvoiceNumber=invoiceNumber; //added by Krishn Prasad on 02 June 2004
        mDeliveryTerms = deliveryTerms;
        mTracking = tracking;
        mShippingMethod = shippingMethod;
        mFlightNumber = flightNumber;
        mFlightRoute = flightRoute;
        mEtd = etd;
        mEta = eta;
        mHawb = hawb;
        mMawb = mawb;

        if( "0".equalsIgnoreCase( cartonCount ) == false )
        {
            mCartonCount = cartonCount;
        }

        if( ( "0.0".equalsIgnoreCase( weight ) == false ) && ( "0.00".equalsIgnoreCase( weight ) == false ) )
        {
            mWeight = weight;
        }
    }

    public boolean getIsSample()
    {
        return isSample;
    }
    public void setIsSample( boolean isSample )
    {
        this.isSample = isSample;
    }

    //Start here Added by Krishna Prasad on 08 June 2004
    public String getStatus() {
        return mstatus;
    }

    public void setStatus(String status) {
        mstatus = status;
    }
    //ends here

    public String getNumber()
    {
        return mNumber;
    }

    public void setNumber( String number )
    {
        mNumber = number;
    }

    public int getCustomerShippingId()
    {
        return mCustomerShippingId;
    }

    public void setCustomerShippingId( int customerShippingId )
    {
        mCustomerShippingId = customerShippingId;
    }


    public int getSalesOrderId()
    {
        return mSalesOrderId;
    }

    public void setSalesOrderId( int salesOrderId )
    {
        mSalesOrderId = salesOrderId;
    }


    public String getSalesOrderNumber()
    {
        return mSalesOrderNumber;
    }

    public void setSalesOrderNumber( String salesOrderNumber )
    {
        mSalesOrderNumber = salesOrderNumber;
    }


    public String getCustomerName()
    {
        return m_customerName;
    }

    public void setCustomerName( String customerName )
    {
        m_customerName = customerName;
    }

    public String getPoNumber()
    {
        return mPONumber;
    }

    public void setPoNumber( String poNumber )
    {
        mPONumber = poNumber;
    }

    public String getWeight()
    {
        return mWeight;
    }

    public void setWeight( String weight )
    {
        mWeight = weight;
    }

    public String getDeliveryTerms()
    {
        return mDeliveryTerms;
    }

    public void setDeliveryTerms( String terms )
    {
        mDeliveryTerms = terms;
    }

    public String getCartonCount()
    {
        return mCartonCount;
    }

    public void setCartonCount( String cartonCount )
    {
        mCartonCount = cartonCount;
    }

    public String getTrackingAsString()
    {
        return StringUtils.concatStrings( mTracking, ";" );
    }

    public String[] getTracking()
    {
        if( mTracking == null)
        {
            return mTracking;
        }

        if( ( mTracking.length <= 0 ) || ( mTracking.length >= 2 ) )
        {
            return mTracking;
        }

        if( mTracking.length == 1 )
        {
            if( ( mTracking[0] == null ) || ( mTracking[0].trim().length() == 0 ) )
            {
                return mTracking;
            }
            else if( mTracking[0].indexOf( ';' ) != -1 )
            {
                String[] temp = null;
                boolean success = false;
                try
                {
                    temp = StringUtils.toStringArray( mTracking[0], ";" );
                    success = true;
                }
                catch( Exception e )
                {
                    System.out.println( "Exception while converting " + mTracking[0] + ", into an array" );
                    e.printStackTrace();
                }

                if( success )
                {
                    return temp;
                }

                return mTracking;
            }
        }

        return mTracking;
    }

    public void setTracking( String[] tracking )
    {
        mTracking = tracking;
    }

    public String getShippingMethod()
    {
        return mShippingMethod;
    }

    public void setShippingMethod( String shippingMethod )
    {
        mShippingMethod = shippingMethod;
    }

    public String getInvoiceNumber()
    {
        return mInvoiceNumber;
    }

    public void setInvoiceNumber( String invoiceNumber ) //added by Krishna Prasad on 02 June 2004
    {
        mInvoiceNumber = invoiceNumber;
    }

    public void setInvNo( String invoiceNumber )
    {
        mInvoiceNumber = invoiceNumber;
    }


    public String getFlightNumber()
    {
        return mFlightNumber;
    }

    public void setFlightNumber( String flightNumber )
    {
        mFlightNumber = flightNumber;
    }

    public String getFlightRoute()
    {
        return mFlightRoute;
    }

    public void setFlightRoute( String flightRoute )
    {
        mFlightRoute = flightRoute;
    }

    public String getEtd()
    {
        return mEtd;
    }

    public void setEtd( String etd )
    {
        mEtd = etd;
    }

    public String getEta()
    {
        return mEta;
    }

    public void setEta( String eta )
    {
        mEta = eta;
    }

    public String getHawb()
    {
        return mHawb;
    }

    public void setHawb( String hawb )
    {
        mHawb = hawb;
    }

    public String getMawb()
    {
        return mMawb;
    }

    public void setMawb( String mawb )
    {
        mMawb = mawb;
    }

    public String getShowSendShipAlertLink()
    {
        return mShowSendShipAlertLink;
    }

    public void setShowSendShipAlertLink( String showSendShipAlertLink )
    {
        mShowSendShipAlertLink = showSendShipAlertLink;
    }

    public HashMap getPulledLotMap()
    {
        return mPulledLotMap;
    }

    public void setPulledLotMap( HashMap pulledLotMap )
    {
        mPulledLotMap = pulledLotMap;
    }

    public String getPaletteCount()  //Added by varma 15 oct 2004
    {
        return mPaletteCount;
    }

    public void setPaletteCount( String paletteCount )
    {
        mPaletteCount = paletteCount;
    }

    public String getPackedby()  //Added by Gandhi on 8th Dec 2004
    {
        return mPackedby;
    }

    public void setPackedby( String packedby )
    {
        mPackedby = packedby;
    }

    public String getTitle()  //Added by Gandhi on 8th Dec 2004
    {
        return mTitle;
    }

    public void setTitle( String title )
    {
        mTitle = title;
    }


    public boolean isDropShippment()
	{
		return mDropShippment;
	}

	public void setDropShippment( boolean b )
	{
		mDropShippment = b;
	}

    public ArrayList getLineitems() {
        return mLineItems;
    }

    public void setLineitems(ArrayList list)
    {
        mLineItems = list;
    }

    public int getShippingFromLocationId() {
        return mshippingFromLocationId;
    }

    public void setShippingFromLocationId(int shippingFromLocationId)
    {
        mshippingFromLocationId = shippingFromLocationId;
    }

    public String getShipDate() {
        return mshipDate;
    }

    public void setShipDate(String shipDate) {
        mshipDate = shipDate;
    }

    public HashMap getFinalInventoryDataMap()
    {
        return mfinalInventoryDataMap;
    }

    public void setFinalInventoryDataMap(HashMap finalInventoryDataMap)
    {
        mfinalInventoryDataMap = finalInventoryDataMap;
    }

    public String getShippingInstructions()
    {
        return mshippingInstructions;
    }

    public void setShippingInstructions(String shippingInstructions)
    {
        mshippingInstructions = shippingInstructions;
    }

    public String getComments()
    {
        return mcomments;
    }

    public void setComments(String comments)
    {
        mcomments = comments;
    }

    public boolean isViewInventory() {
        return viewInventory;
    }

    public void setViewInventory(boolean viewInventory) {
        this.viewInventory = viewInventory;
    }

    public boolean isModifyInventory() {
        return modifyInventory;
    }

    public void setModifyInventory(boolean modifyInventory) {
        this.modifyInventory = modifyInventory;
    }

    public boolean isRunAdaptor() {
        return runAdaptor;
    }

    public void setRunAdaptor(boolean runAdaptor) {
        this.runAdaptor = runAdaptor;
    }

    public String getExternalUserId() {
        return externalUserId;
    }

    public void setExternalUserId(String externalUserId) {
        this.externalUserId = externalUserId;
    }

    public String getGeneratedPackingSlipPdfURL() {
        return mgeneratedPackingSlipPdfURL;
    }

    public void setGeneratedPackingSlipPdfURL(String generatedPackingSlipPdfURL) {
        this.mgeneratedPackingSlipPdfURL = generatedPackingSlipPdfURL;
    }

    public String getGeneratedCommercialInvoicePdfURL() {
        return mgeneratedCommercialInvoicePdfURL;
    }

    public void setGeneratedCommercialInvoicePdfURL(String generatedCommercialInvoicePdfURL) {
        this.mgeneratedCommercialInvoicePdfURL = generatedCommercialInvoicePdfURL;
    }

    public String getFreightInstructions() {
        return mfreightInstructions;
    }

    public void setFreightInstructions(String mfreightInstructions) {
        this.mfreightInstructions = mfreightInstructions;
    }

    public void reset( ActionMapping mapping, HttpServletRequest request )
    {

        mTracking = new String[] {""};

        if( mLineItems == null || mLineItems.isEmpty() == true )
        {
            mLineItems = new ArrayList();
        }

        if(  mfinalInventoryDataMap == null || mfinalInventoryDataMap.isEmpty() == true )
        {
            mfinalInventoryDataMap = new HashMap();
        }
    }

    public int getOdmId() {
        return odmId;
    }

    public void setOdmId(int odmId) {
        this.odmId = odmId;
    }

    public String getOdm() {
        return odm;
    }

    public void setOdm(String odm) {
        this.odm = odm;
    }

    public boolean isConfrimPackingSlip() {
        return confrimPackingSlip;
    }

    public void setConfrimPackingSlip(boolean confrimPackingSlip) {
        this.confrimPackingSlip = confrimPackingSlip;
    }

    public ClientInfo getClientInfo() {
        return clientInfo;
    }

    public void setClientInfo(ClientInfo clientInfo) {
        this.clientInfo = clientInfo;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public String getVendorName() {
        return vendorName;
    }

    public void setVendorName(String vendorName) {
        this.vendorName = vendorName;
    }

    public String getContactPerson() {
        return contactPerson;
    }

    public void setContactPerson(String contactPerson) {
        this.contactPerson = contactPerson;
    }

    public String getSupplierNumber() {
        return supplierNumber;
    }

    public void setSupplierNumber(String supplierNumber) {
        this.supplierNumber = supplierNumber;
    }

    public String getOdmSupplierNumber() {
        return odmSupplierNumber;
    }

    public void setOdmSupplierNumber(String odmSupplierNumber) {
        this.odmSupplierNumber = odmSupplierNumber;
    }

    public int getShippingToAddressId() {
        return shippingToAddressId;
    }

    public void setShippingToAddressId(int shippingToAddressId) {
        this.shippingToAddressId = shippingToAddressId;
    }

    public int getBillingAddressId() {
        return billingAddressId;
    }

    public void setBillingAddressId(int billingAddressId) {
        this.billingAddressId = billingAddressId;
    }

    public int getShippingFromAddressId() {
        return shippingFromAddressId;
    }

    public void setShippingFromAddressId(int shippingFromAddressId) {
        this.shippingFromAddressId = shippingFromAddressId;
    }

    public String getBillingAddress() {
        return billingAddress;
    }

    public void setBillingAddress(String billingAddress) {
        this.billingAddress = billingAddress;
    }

    public String getShippingAddress() {
        return shippingAddress;
    }

    public void setShippingAddress(String shippingAddress) {
        this.shippingAddress = shippingAddress;
    }

    public String getLetterOfCreditNo() {
        return letterOfCreditNo;
    }

    public void setLetterOfCreditNo(String letterOfCreditNo) {
        this.letterOfCreditNo = letterOfCreditNo;
    }

    public Address getShippingAddressObject() {
        return m_shippingAddressObject;
    }

    public void setShippingAddressObject(Address shippingAddressObject) {
        this.m_shippingAddressObject = shippingAddressObject;
    }

    public Address getShippersAddressObject() {
        return m_shippersAddressObject;
    }

    public void setShippersAddressObject(Address shippersAddressObject) {
        this.m_shippersAddressObject = shippersAddressObject;
    }

    public Address getBillingAddressObject() {
        return m_billingAddressObject;
    }

    public void setBillingAddressObject(Address billingAddressObject) {
        this.m_billingAddressObject = billingAddressObject;
    }

    public HashMap getFinalInventoryDataMapView() {
        return finalInventoryDataMapView;
    }

    public void setFinalInventoryDataMapView(HashMap finalInventoryDataMapView) {
        this.finalInventoryDataMapView = finalInventoryDataMapView;
    }

    public String getClientAddrWithOutEmailObjFormattedAirgo()
    {
        Address add = clientInfo.getAddress();
        StringBuffer formatAddress = new StringBuffer();

        if( add != null )
        {
            if( clientInfo.getClientName() != null && clientInfo.getClientName().trim().length() > 0 )
            {
                if( ( add.getAddress1() != null && !"".equalsIgnoreCase( add.getAddress1().trim() ) ) || ( add.getAddress2() != null && !"".equalsIgnoreCase( add.getAddress2().trim() ) ) )
                {
                    formatAddress.append ( "<BR>" );
                }
            }

            if( add.getAddress1() != null && !( add.getAddress1().trim().length() == 0 ) )
            formatAddress.append ( add.getAddress1().trim() );

            if( ( add.getAddress1() != null && !( add.getAddress1().trim().length() == 0 ) ) && ( add.getAddress2() != null && !( add.getAddress2().trim().length() == 0 ) ) )
            formatAddress.append ( ", " );

            if( add.getAddress2() != null && !( add.getAddress2().trim().length() == 0 ) )
            formatAddress.append ( add.getAddress2().trim() );

            if( ( add.getAddress3() != null && !"".equalsIgnoreCase( add.getAddress3().trim() ) ) || ( add.getAddress4() != null && !"".equalsIgnoreCase( add.getAddress4().trim() ) ) )
            formatAddress.append ( "<BR>" );

            if( ( add.getAddress3() != null && !"".equalsIgnoreCase( add.getAddress3().trim() ) ) )
            formatAddress.append ( add.getAddress3().trim() );

            if( add.getAddress3() != null && !"".equalsIgnoreCase( add.getAddress3().trim() ) && add.getAddress4() != null && !"".equalsIgnoreCase( add.getAddress4().trim() ) )
            formatAddress.append ( ", " );

            if( ( add.getAddress4() != null && !"".equalsIgnoreCase( add.getAddress4().trim() ) ) )
            formatAddress.append ( add.getAddress4().trim() );

            StringBuffer cityStateZip = new StringBuffer ( "" );

            if ( add.getCity() != null && !"".equals ( add.getCity().trim() ) ) cityStateZip.append ( add.getCity().trim() );

            // add ',' only if city, state, zip are not empty
            if ( add.getCity() != null && !"".equals ( add.getCity().trim() ) && ( ( add.getState() != null && !"".equals( add.getState().trim() ) ) || ( add.getZipCode() != null && !"".equals( add.getZipCode().trim() ) ) ) ) cityStateZip.append ( ", " );

            if ( add.getState() != null && !"".equals( add.getState().trim() ) ) cityStateZip.append( add.getState().trim() );

            // Add '-' only if there is state and Zip also
            if ( add.getState() != null && !"".equals( add.getState().trim() ) && add.getZipCode() != null && !"".equals( add.getZipCode().trim() ) ) cityStateZip.append ( " - " );

            if ( add.getZipCode() != null && !"".equals ( add.getZipCode().trim() ) ) cityStateZip.append ( add.getZipCode ().trim() );

            // add ',' if any of the above is present
            if ( ( ( add.getCity() != null && !"".equals( add.getCity().trim() ) ) || !"".equals( add.getState().trim() ) || !"".equals ( add.getZipCode() ) ) && !"".equalsIgnoreCase( add.getCountry () ) ) cityStateZip.append ( ", " );
            cityStateZip.append ( add.getCountry () );

            if( cityStateZip.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + cityStateZip );
            }

            StringBuffer phFax = new StringBuffer ();
            if( add.getPhoneNumber() != null && !"".equals( add.getPhoneNumber().trim() ) ) phFax.append ( "T:" + add.getPhoneNumber().trim() );
            if( add.getPhoneNumber() != null && !"".equals( add.getPhoneNumber().trim() ) && add.getFaxNumber() != null && !add.getFaxNumber().equals ( "" ) ) phFax.append ( ",&nbsp;" );
            if( add.getFaxNumber() != null && !"".equals( add.getFaxNumber().trim() ) ) phFax.append ( "F:" + add.getFaxNumber().trim() );

            if( phFax.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + phFax );
            }
        }
        return formatAddress.toString() ;
    }

    public String getShippersAddressObjectFormattedAirgo()
	{
		StringBuffer formatedAddress = new StringBuffer();
		formatedAddress.append( getFormattedAddressAirgo ( m_shippersAddressObject ) );
		return formatedAddress.toString();
	}
    public String getShippingAddressObjectFormattedAirgo()
    {
        StringBuffer formatedAddress = new StringBuffer();
        if ( odm != null && odm.trim().length() > 0 )
        {
             if( m_shippingAddressObject != null && m_shippingAddressObject.getContactPerson() != null && !m_shippingAddressObject.getContactPerson().equalsIgnoreCase( odm ) )
            {
                if( odm != null && odm.trim().length() > 0 )
                {
                    formatedAddress.append( odm );
                    if( m_shippingAddressObject != null && ( m_shippingAddressObject.getContactPerson() != null ) && ( m_shippingAddressObject.getContactPerson().trim().length() > 0 ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                    formatedAddress.append( m_shippingAddressObject.getContactPerson() );

                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
                else
                {
                    formatedAddress.append( m_shippingAddressObject.getContactPerson() );
                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
            else
            {
                if( odm != null && odm.trim().length() > 0 )
                {
                    formatedAddress.append( odm );
                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
        }
        else
        {
            if( m_shippingAddressObject != null && m_shippingAddressObject.getContactPerson() != null && !m_shippingAddressObject.getContactPerson().equalsIgnoreCase( m_customerName ) )
            {
                if( m_customerName != null && m_customerName.trim().length() > 0 )
                {
                    formatedAddress.append( m_customerName );
                    if( m_shippingAddressObject != null && ( m_shippingAddressObject.getContactPerson() != null ) && ( m_shippingAddressObject.getContactPerson().trim().length() > 0 ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                    formatedAddress.append( m_shippingAddressObject.getContactPerson() );

                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
                else
                {
                    formatedAddress.append( m_shippingAddressObject.getContactPerson() );
                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
            else
            {
                if( m_customerName != null && m_customerName.trim().length() > 0 )
                {
                    formatedAddress.append( m_customerName );
                    if( m_shippingAddressObject != null && ( ( ( m_shippingAddressObject.getAddress1() != null ) && ( m_shippingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_shippingAddressObject.getAddress2() != null ) && ( m_shippingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
        }

        formatedAddress.append( getFormattedAddressAirgo( m_shippingAddressObject ) );
        return formatedAddress.toString();
    }

    public String getBillingAddressObjectFormattedAirgo()
    {
        StringBuffer formatedAddress = new StringBuffer();
        if( m_billingAddressObject != null && m_billingAddressObject.getContactPerson() != null && !m_billingAddressObject.getContactPerson().equalsIgnoreCase( m_customerName ) )
        {
            if( m_customerName != null && m_customerName.trim().length() > 0 )
            {
                formatedAddress.append( m_customerName );
                if( m_billingAddressObject != null && ( m_billingAddressObject.getContactPerson() != null ) && ( m_billingAddressObject.getContactPerson().trim().length() > 0 ) )
                {
                    formatedAddress.append( "<BR>" );
                }
                formatedAddress.append( m_billingAddressObject.getContactPerson() );

                if( m_billingAddressObject != null && ( ( ( m_billingAddressObject.getAddress1() != null ) && ( m_billingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_billingAddressObject.getAddress2() != null ) && ( m_billingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
            else
            {
                formatedAddress.append( m_billingAddressObject.getContactPerson() );
                if( m_billingAddressObject != null && ( ( ( m_billingAddressObject.getAddress1() != null ) && ( m_billingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_billingAddressObject.getAddress2() != null ) && ( m_billingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
        }
        else
        {
            if( m_customerName != null && m_customerName.trim().length() > 0 )
            {
                formatedAddress.append( m_customerName );
                if( m_billingAddressObject != null && ( ( ( m_billingAddressObject.getAddress1() != null ) && ( m_billingAddressObject.getAddress1().trim().length() > 0 ) ) || ( ( m_billingAddressObject.getAddress2() != null ) && ( m_billingAddressObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
        }
        formatedAddress.append( getFormattedAddressAirgo( m_billingAddressObject ) );
        return formatedAddress.toString();
    }


    public String getFormattedAddressAirgo( Address add )
    {
        StringBuffer formatAddress = new StringBuffer();

        if( add != null )
        {
            if( add.getAddress1() != null )
            formatAddress.append ( add.getAddress1() );

            if( add.getAddress1() != null && !( add.getAddress1().trim().length() == 0 ) && add.getAddress2() != null && !( add.getAddress2().trim().length() == 0 ) )
            formatAddress.append ( ", " );

            if( add.getAddress2() != null )
            formatAddress.append ( add.getAddress2() );

            if( ( add.getAddress3() != null && !add.getAddress3().trim().equalsIgnoreCase( "" ) ) || ( add.getAddress4() != null && !add.getAddress4().trim().equalsIgnoreCase( "" ) ) )
            formatAddress.append ( "<BR>" );

            if( add.getAddress3() != null )
            formatAddress.append ( add.getAddress3 () );

            if( add.getAddress3() != null && !add.getAddress3().trim().equalsIgnoreCase( "" ) && add.getAddress4() != null && !add.getAddress4().trim().equalsIgnoreCase( "" ) )
            formatAddress.append ( ", " );

            if( add.getAddress4() != null )
            formatAddress.append ( add.getAddress4() );

            StringBuffer cityStateZip = new StringBuffer ( "" );

            if ( add.getCity()!= null && !( "".equals( add.getCity().trim() ) ) ) cityStateZip.append ( add.getCity().trim() );

            // add ',' only if city, state, zip are not empty
            if ( add.getCity() != null && !( "".equals( add.getCity().trim() ) ) && ( ( add.getState() != null && !( "".equals( add.getState().trim() ) ) ) || ( add.getZipCode() != null && !( "".equals( add.getZipCode().trim() ) ) ) ) ) cityStateZip.append ( ", " );

            if ( add.getState() != null && !( "".equals( add.getState().trim() ) ) ) cityStateZip.append( add.getState().trim() );

            // Add '-' only if there is state and Zip also
            if ( add.getState() != null && !"".equals( add.getState().trim() ) && add.getZipCode() != null && !"".equals( add.getZipCode ().trim() ) ) cityStateZip.append ( " - " );
            if ( add.getZipCode() != null && !"".equals( add.getZipCode().trim() ) ) cityStateZip.append ( add.getZipCode().trim() );
            // add ',' if any of the above is present
            if ( ( ( add.getCity() != null && !"".equals( add.getCity().trim() ) ) || ( add.getState() != null && !"".equals( add.getState().trim() ) ) || ( add.getZipCode() != null && !"".equals( add.getZipCode().trim() ) ) ) && ( add.getCountry() != null && !"".equalsIgnoreCase( add.getCountry().trim() ) ) ) cityStateZip.append ( ", " );

            if( add.getCountry() != null )
            cityStateZip.append ( add.getCountry().trim() );

            if( cityStateZip.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + cityStateZip );
            }

            StringBuffer phFax = new StringBuffer ();
            if( add.getPhoneNumber() != null && !"".equals( add.getPhoneNumber().trim() ) ) phFax.append ( "T:" + add.getPhoneNumber().trim() );
            if( add.getPhoneNumber() != null && !"".equals( add.getPhoneNumber().trim() ) && add.getFaxNumber() != null && !"".equals( add.getFaxNumber().trim() ) ) phFax.append ( ",&nbsp;" );

            if( add.getFaxNumber() != null && !"".equals( add.getFaxNumber().trim() ) ) phFax.append ( "F:" + add.getFaxNumber().trim() );

            if( phFax.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + phFax );
            }

            if(  add.getEmail() != null && add.getEmail().trim().length() > 0 )
            {
                formatAddress.append ( "<BR>Email:" + add.getEmail().trim() );
            }
        }
        return formatAddress.toString() ;
    }

    public String getClientAddrWithOutEmailObjFormatted()
	{
        Address add = clientInfo.getAddress();
        StringBuffer formatAddress = new StringBuffer();

        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );
        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );
        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );
        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );
        formatAddress.append ( ( ( add.getCity() == null ) || ( add.getCity().trim().length()==0 ) ) ? "" : "<BR>" +  add.getCity() );
        String formatState = PackingSlipForm.getFormatedState(add);
        if ( formatState.trim().length() !=0 )
           formatAddress.append ("<br>"+formatState);
        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );

        return formatAddress.toString() ;
	}
    public String getClientAddressObjectFormatted()
	{
		return getFormattedClientAddress( clientInfo.getAddress() );
	}

    public String getShippingAddressObjectFormatted()
    {
        return getFormattedAddress( m_shippingAddressObject );
    }

    public String getTermsForHtmlView()
	{
		if( ( mDeliveryTerms == null ) || ( mDeliveryTerms.trim().length() == 0 ) )
		{
			mDeliveryTerms = "";
		}
		return mDeliveryTerms;
	}
    public String getFormattedAddress( Address add )
    {
        StringBuffer formatAddress = new StringBuffer();
        formatAddress.append ( ( ( add.getContactPerson() == null ) || ( ( add.getContactPerson().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getContactPerson() );
        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );

        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );

        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );

        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );

        formatAddress.append ( ( ( add.getCity() == null ) || ( add.getCity().trim().length()==0 ) ) ? "" : "<BR>" +  add.getCity() );

        String formatedState = PackingSlipForm.getFormatedState( add ); // Added by neelima
        if ( formatedState.trim().length() > 0 )
            formatAddress.append ( "<br>" + formatedState );

        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR><BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getCellNumber() != null ) && ( add.getCellNumber().trim().length() > 0 ) ) ? "<BR>Cell No: "+ add.getCellNumber() : "");
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );
        formatAddress.append ( ( ( add.getEmail() != null ) && ( add.getEmail().trim().length() > 0 ) ) ?  "<BR>Email: "+ add.getEmail() : "" );


        return formatAddress.toString() ;
    }

    public String getFormattedClientAddress( Address add )
    {
        StringBuffer formatAddress = new StringBuffer();

        formatAddress.append ( ( ( add.getContactPerson() == null ) || ( ( add.getContactPerson().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getContactPerson() );
        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );
        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );
        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );
        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );
        formatAddress.append ( ( ( add.getCity() == null ) || ( add.getCity().trim().length()==0 ) ) ? "" : "<BR>" +  add.getCity() );
        String formatState = PackingSlipForm.getFormatedState(add);
        if ( formatState.trim().length() !=0 )
           formatAddress.append ("<br>"+formatState);
        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR><BR>Tel: "+ add.getPhoneNumber() : ""  );
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "");
        formatAddress.append ( ( ( add.getEmail() != null ) && ( add.getEmail().trim().length() > 0 ) ) ?  "<BR>Email: "+ add.getEmail() : "" );

        return formatAddress.toString() ;
    }

    public String getShippingInstructionsObjectFormatted()
    {
		return formatLines( mshippingInstructions, 50);
	}
    String formatLines( String targetString, int maxLength )
    {
        String formatedString = "";
        if( targetString != null && targetString.trim().length() > 0 )
        {
            for ( int i = 0; i < targetString.length(); i++ )
            {
                if( ( ( i + 1 ) % maxLength ) == 0 )
                {
                    formatedString = formatedString + "<br>&nbsp;";
                    formatedString = formatedString + targetString.substring( i, i + 1 );
                }
                else
                {
                    formatedString = formatedString + targetString.substring( i, i + 1 );
                }
            }
        }
        return formatedString;
    }
    public String getFreightInstructionsObjectFormatted()
    {
        return formatLines( mfreightInstructions, 50 );
    }

    public String getNoOfBoxesForHtmlView()
	{
		if( ( mCartonCount == null ) || ( mCartonCount.trim().length() == 0 ) || ( "0".equalsIgnoreCase( mCartonCount ) ) )
		{
			mCartonCount = "";
		}
		return mCartonCount;
	}

    public Address getShippingVendorAddressObject() {
        return shippingVendorAddressObject;
    }

    public void setShippingVendorAddressObject(Address shippingVendorAddressObject) {
        this.shippingVendorAddressObject = shippingVendorAddressObject;
    }

    public String getShippingVendorObjectFormatted()
    {
        Address add = shippingVendorAddressObject;
        StringBuffer formatAddress = new StringBuffer();
        formatAddress.append ( ( ( add.getContactPerson() == null ) || ( ( add.getContactPerson().trim().length() == 0 ) ) ) ? "" :"<BR>C/O " +  add.getContactPerson() );
		formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );

		formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );

		formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );

		formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );

		formatAddress.append ( ( ( add.getCity() == null ) || ( add.getCity().trim().length()==0 ) ) ? "" : "<BR>" +  add.getCity() );

		String formatedState = PackingSlipForm.getFormatedState( add );
		if ( formatedState.trim().length() > 0 )
        	formatAddress.append ( "<br>" + formatedState );

        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR><BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getCellNumber() != null ) && ( add.getCellNumber().trim().length() > 0 ) ) ? "<BR>Cell No: "+ add.getCellNumber() : "");
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );
        formatAddress.append ( ( ( add.getEmail() != null ) && ( add.getEmail().trim().length() > 0 ) ) ?  "<BR>Email: "+ add.getEmail() : "" );


		return formatAddress.toString() ;
	}

    public boolean isConsignment() {
        return isConsignment;
    }

    public void setConsignment(boolean consignment) {
        isConsignment = consignment;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }


    public String getWeightType() {
        return weightType;
    }

    public void setWeightType(String weightType) {
        this.weightType = weightType;
    }

    public String getPackageDimension() {
        return packageDimension;
    }

    public void setPackageDimension(String packageDimension) {
        this.packageDimension = packageDimension;
    }

    public String getGrossWeight() {
        return grossWeight;
    }

    public void setGrossWeight(String grossWeight) {
        this.grossWeight = grossWeight;
    }


    public String getUomPkgDimension() {
        return uomPkgDimension;
    }

    public void setUomPkgDimension(String uomPkgDimension) {
        this.uomPkgDimension = uomPkgDimension;
    }


    public String getFlightNumberTwo() {
        return flightNumberTwo;
    }

    public void setFlightNumberTwo(String flightNumberTwo) {
        this.flightNumberTwo = flightNumberTwo;
    }


    public String getFlightNumberOne() {
        return flightNumberOne;
    }

    public void setFlightNumberOne(String flightNumberOne) {
        this.flightNumberOne = flightNumberOne;
    }


    public String getCountryOfFabOrigin() {
        return countryOfFabOrigin;
    }

    public void setCountryOfFabOrigin(String countryOfFabOrigin) {
        this.countryOfFabOrigin = countryOfFabOrigin;
    }

    public String getCountryOfAssyOrigin() {
        return countryOfAssyOrigin;
    }

    public void setCountryOfAssyOrigin(String countryOfAssyOrigin) {
        this.countryOfAssyOrigin = countryOfAssyOrigin;
    }
}


